<?php

/**
 * 微博编辑 
 * 
 * @author zhangchao
 * @since 2012-05-15
 */


include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/foodv2/inc.php");

$g_cgival = array();
$g_pro = array();
$g_show = array();


function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;
	
	cgi::both($g_cgival['status_id'], 'status_id', '');
	$g_cgival['status_id'] = trim($g_cgival['status_id']);
	if($g_cgival['status_id'] == 0 || !is_numeric($g_cgival['status_id']))
	{
		throw new Exception('status_id不合法');
	}
	
}

function get_data()
{
	global $g_cgival, $g_pro, $g_show,$config;

	$site_id = admin::admin_get_user_site_id();
	
	$db = new db_food_status();
	$data = $db->admin_get_status_search_by_status_id($g_cgival['status_id']);
	if(!empty($data[0]))
	{
		$status_info = $data[0];
		
		$db_food_status_tag=new db_food_status_tag();
		$status_info['tag'] = $db_food_status_tag->admin_get_tags_by_status_id($g_cgival['status_id']);
		foreach ($status_info['tag'] as $tag) {
			$status_info['tag_str'] .= $tag['tag'].' ';
		}
		$status_info['tag_str'] = rtrim($status_info['tag_str']);

		// 跳转到前台的url
		$user_global_config =  user_global_config::get_instance();
		$domain = $user_global_config->get_domain_by_site_id($status_info["site_id"]);
		if ($status_info["is_rstrt"] == 1)
		{
			$status_info["share_url"] = "http://{$domain}/explore/detail-{$status_info["status_id"]}.html";
		}
		else
		{
			$status_info["share_url"] = "http://{$domain}/show/detail-{$status_info["status_id"]}.html";
		}
		
		$g_show['data'] = $status_info;
	}
	else
	{
		throw new Exception('该分享不存在或已被删除');
	}
}

$g_show["error"] = 0;
$g_show["errmsg"] = '';
try
{
	admin_check_login();
// 	admin_check_user_priv("foodv2/album_list.php");
	check_cgi_pro();
	get_data();
	$g_show["error"] = 0;
	$g_show["errmsg"] = '';
}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}

show_pro();
exit;


function show_pro()
{
	global $g_cgival, $g_pro, $g_show;
	
	if(isset($_GET['debug']))
		print_r($g_show);
	
	$smarty = p_get_smarty ();
	$smarty->assign ( 'g_show', $g_show );
	if ($g_show["error"] == 1)
	{
		$smarty->display("admin_error.html");
		return;
	}
	$smarty->display ( "foodv2/mblog/edit_food_status.html" );
}
?>